using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RaidLog.WebClient
{
    static class Program
    {
        private static RaidLog.Engine.WowInstallation _WowApplication = null;

        public static RaidLog.Engine.WowInstallation WowApplication
        {
            get { return Program._WowApplication; }
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string wowhome = Properties.Settings.Default.WowAppHome;
            while (null == _WowApplication)
            {
                try
                {
                    _WowApplication = new RaidLog.Engine.WowInstallation(wowhome);
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show(ex.Message, "WoW Logs Not Found!", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand) == DialogResult.OK)
                    {
                        FolderBrowserDialog folderbrowser = new FolderBrowserDialog();
                        if (folderbrowser.ShowDialog() == DialogResult.OK)
                        {
                            wowhome = folderbrowser.SelectedPath;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
            if (wowhome != Properties.Settings.Default.WowAppHome)
            {
                Properties.Settings.Default.WowAppHome = wowhome;
                Properties.Settings.Default.Save();
            }

            ImportData.ImportDataSrv _Server = new RaidLog.WebClient.ImportData.ImportDataSrv();

            Application.Run(new Database(_Server));
        }
    }
}